//
//  JsMd5Manager.m
//  JsUtilitySdk
//
//  Created by Gikki Ares on 2023/4/12.
//

#import "JsMd5Manager.h"
#import <CommonCrypto/CommonDigest.h>

@implementation JsMd5Manager

#pragma mark - 32位 小写
+(NSString *)md5LowerCase32:(NSString *)str{
		//要进行UTF8的转码
	const char* input = [str UTF8String];
	unsigned char result[CC_MD5_DIGEST_LENGTH];
	CC_MD5(input, (CC_LONG)strlen(input), result);
	NSMutableString *digest = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
	for (NSInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
		[digest appendFormat:@"%02x", result[i]];
	}
	return digest;
}


#pragma mark - 16位 小写
+(NSString *)md5LowerCase16:(NSString *)str{
	NSString *md5Str = [self md5LowerCase32:str];
	NSString  *string = [md5Str substringWithRange:NSMakeRange(8, 16)];
	return string;
}


	// 32位小写
+(NSString *)md5LowerCase32:(NSString *)str salt:(NSString *)salt {
	NSString * input = [NSString stringWithFormat:@"%@%@",str,salt];
	return [self md5LowerCase32:input];
}
	// 16为大写
+(NSString *)md5LowerCase16:(NSString *)str salt:(NSString *)salt {
	return [self md5LowerCase16:str];
}

@end
